const http = require("http");

const server = http.createServer((request, response) => {
  const { method } = request;
  const { pathname } = new URL(request.url, "http://127.0.0.1");

  response.setHeader("content-type", "text/html;charset=utf-8");

  if (method === "GET" && pathname === "/login") {
    response.end("登录页面");
  } else if (method === "GET" && pathname === "/reg") {
    response.end("注册页面");
  } else {
    // 防止其他请求一直连接服务器
    response.end("not found");
  }
});

server.listen(9000, () => {
  console.log("服务启动");
});
